package com.deman.framework.rpc.core;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class SpringContextHodler implements ApplicationContextAware {
    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringContextHodler.applicationContext = applicationContext;
    }

    public static Object getBean(String beanName) {
        return applicationContext.getBean(beanName);
    }
    public static Object getBean(Class clz) {
        Map <String, Object> result = applicationContext.getBeansOfType(clz);
        return result.values().stream().filter((e)->{ return !(e instanceof MessageSendProxy);}).findFirst().get();
    }

}
